# −*− coding: UTF−8 −*−
from optparse import make_option
from django.core.management.base import NoArgsCommand
from django.conf import settings
SLEEP_TIME = getattr(settings,'SLEEP_TIME', 120)

class Command(NoArgsCommand):
    option_list = NoArgsCommand.option_list + (
        make_option('--limit', dest='limit', default=0, type='int',
            help='process at most this many records. default is 0 (unlimited).'),
        make_option('--order-by', dest='order_by', action='store', default='?', help="order by which field?"),
        make_option('--sleep-time', dest='sleep_time', action='store', default=SLEEP_TIME, help="How long should i sleep if there is nothing to do?"),
        
    )
    help = "run some jobs from the ticket queue"
    
    def handle_noargs(self, *args, **options):        
        verbosity=int(options.get('verbosity', 0)) #django has a lame verbosity opt
        limit = options.get('limit')
        order_by = options.get('order_by')
        sleep_time = options.get('sleep_time')
        
        from ticket.queue_processors import process_queue
        
        process_queue(limit=limit, order_by=order_by, verbosity=verbosity, sleep_time=sleep_time)
